#include "problem1.h"
#include "mvfcpp.h"
#include <stdio.h>
#include <math.h>
//##############################################################################3
void problem1::initFun()
{
     //1st name
     //2nd 0 if dim is n(arbitrary), if 0 noticeand loop for some value ex. 4 and 7
     //3rd true if min known
     //4th min, ignored if 4th 0
     //5th true if all x_i the same boundry
     //6th vector ofboundries

     fun.push_back(Function("mvfAckley",7,true,0,true));//################################################ANY
     fun[0].bounds.push_back(-30);
     fun[0].bounds.push_back(30);
     for(int i=0; i<7; i++)
          fun[0].atPoint.push_back(0);


     fun.push_back( Function("mvfBeale",2,true,0,true));
     fun[1].bounds.push_back(-4.5);
     fun[1].bounds.push_back(4.5);
     fun[1].atPoint.push_back(3);
     fun[1].atPoint.push_back(0.5);

     fun.push_back( Function("mvfBohachevsky1",2,true,0,true));
     fun[2].bounds.push_back(-50);
     fun[2].bounds.push_back(50);
     fun[2].atPoint.push_back(0);
     fun[2].atPoint.push_back(0);

     fun.push_back( Function("mvfBohachevsky2",2,true,0,true));
     fun[3].bounds.push_back(-50);
     fun[3].bounds.push_back(50);
     fun[3].atPoint.push_back(0);
     fun[3].atPoint.push_back(0);

     fun.push_back( Function("mvfBooth",2,true,0,true));
     fun[4].bounds.push_back(-10);
     fun[4].bounds.push_back(10);
     fun[4].atPoint.push_back(1);
     fun[4].atPoint.push_back(3);

     fun.push_back( Function("mvfBoxBetts",3,true,0,false));
     fun[5].bounds.push_back(0.9);
     fun[5].bounds.push_back(1.2);
     fun[5].bounds.push_back(9);
     fun[5].bounds.push_back(11.2);
     fun[5].bounds.push_back(0.9);
     fun[5].bounds.push_back(1.2);
     fun[5].atPoint.push_back(1);
     fun[5].atPoint.push_back(10);
     fun[5].atPoint.push_back(1);

     fun.push_back( Function("mvfBranin",2,true,0.397889,false));
     fun[6].bounds.push_back(-5);
     fun[6].bounds.push_back(10);
     fun[6].bounds.push_back(0);
     fun[6].bounds.push_back(15);
     fun[6].atPoint.push_back(-3.142);
     fun[6].atPoint.push_back(12.275);
     fun[6].atPoint.push_back(3.142);
     fun[6].atPoint.push_back(2.275);
     fun[6].atPoint.push_back(9.425);
     fun[6].atPoint.push_back(2.425);

     fun.push_back( Function("mvfBranin2",2,true,0,true));
     fun[7].bounds.push_back(0);
     fun[7].bounds.push_back(10);
     fun[7].atPoint.push_back(0.402357);
     fun[7].atPoint.push_back(0.287408);

     fun.push_back( Function("mvfCamel3",2,true,-321.031,true));
     fun[8].bounds.push_back(-5);
     fun[8].bounds.push_back(5);
     fun[8].atPoint.push_back(0);
     fun[8].atPoint.push_back(0);

     fun.push_back( Function("mvfCamel6",2,true,-1.0316285,true));
     fun[9].bounds.push_back(-5);
     fun[9].bounds.push_back(5);
     fun[9].atPoint.push_back(0.089883);
     fun[9].atPoint.push_back(-0.7126);

     fun.push_back( Function("mvfChichinadze",2,true,-110.02,false));
     fun[10].bounds.push_back(-30);
     fun[10].bounds.push_back(30);
     fun[10].bounds.push_back(-10);
     fun[10].bounds.push_back(10);
     fun[10].atPoint.push_back(5.90133);
     fun[10].atPoint.push_back(0.5);


     fun.push_back( Function("mvfCola",17,true,11.7464,true));
     fun[11].bounds.push_back(-4);
     fun[11].bounds.push_back(4);



     fun.push_back( Function("mvfColville",4,true,0,true));
     fun[12].bounds.push_back(-10);
     fun[12].bounds.push_back(10);
     for(int i=0; i<4; i++)
          fun[12].atPoint.push_back(1);


     fun.push_back( Function("mvfCorana",4,true,0,true));
     fun[13].bounds.push_back(-100);
     fun[13].bounds.push_back(100);
     fun[13].atPoint.push_back(1);
     fun[13].atPoint.push_back(1000);
     fun[13].atPoint.push_back(10);
     fun[13].atPoint.push_back(100);

     fun.push_back( Function("mvfEasom",2,true,-1,true));
     fun[14].bounds.push_back(-100);
     fun[14].bounds.push_back(100);
     fun[14].atPoint.push_back(3.1416);
     fun[14].atPoint.push_back(3.1416);

     fun.push_back( Function("mvfStep",30,true,0,true));
     fun[15].bounds.push_back(-100);
     fun[15].bounds.push_back(100);
     for(int i=0; i<30; i++)
          fun[15].atPoint.push_back(0.5);

     fun.push_back( Function("mvfExp2",2,true,0,true));
     fun[16].bounds.push_back(0);
     fun[16].bounds.push_back(20);
     fun[16].atPoint.push_back(1);
     fun[16].atPoint.push_back(10);

     fun.push_back( Function("mvfGear",4,true,2.7e-12,true));
     fun[17].bounds.push_back(12);
     fun[17].bounds.push_back(60);
     fun[17].atPoint.push_back(16);
     fun[17].atPoint.push_back(19);
     fun[17].atPoint.push_back(43);
     fun[17].atPoint.push_back(49);

     fun.push_back( Function("mvfGoldsteinPrice",2,true,3,true));
     fun[18].bounds.push_back(-2);
     fun[18].bounds.push_back(2);
     fun[18].atPoint.push_back(0);
     fun[18].atPoint.push_back(1);

     fun.push_back( Function("mvfGriewank",10,true,0,true));
     fun[19].bounds.push_back(-600);
     fun[19].bounds.push_back(600);
     for(int i=0; i<10; i++)
          fun[19].atPoint.push_back(0);


     fun.push_back( Function("mvfHansen",2,true,-176.54,true));
     fun[20].bounds.push_back(-10);
     fun[20].bounds.push_back(10);


     fun.push_back( Function("mvfHartman3",3,true,-3.86,true));
     fun[21].bounds.push_back(0);
     fun[21].bounds.push_back(1);
     fun[21].atPoint.push_back(0.114);
     fun[21].atPoint.push_back(0.556);
     fun[21].atPoint.push_back(0.852);


     fun.push_back( Function("mvfHartman6",6,true,-3.32,true));
     fun[22].bounds.push_back(0);
     fun[22].bounds.push_back(1);
     fun[22].atPoint.push_back(0.201);
     fun[22].atPoint.push_back(0.15);
     fun[22].atPoint.push_back(0.477);
     fun[22].atPoint.push_back(0.275);
     fun[22].atPoint.push_back(0.311);
     fun[22].atPoint.push_back(0.657);

     fun.push_back( Function("mvfHimmelblau",2,true,0,true));
     fun[23].bounds.push_back(-5);
     fun[23].bounds.push_back(5);
     fun[23].atPoint.push_back(3);
     fun[23].atPoint.push_back(2);

     fun.push_back( Function("mvfHolzman1",3,true,-405,false));
     fun[24].bounds.push_back(0.1);
     fun[24].bounds.push_back(100);
     fun[24].bounds.push_back(0);
     fun[24].bounds.push_back(25.6);
     fun[24].bounds.push_back(0);
     fun[24].bounds.push_back(5);
     fun[24].atPoint.push_back(50);
     fun[24].atPoint.push_back(25);
     fun[24].atPoint.push_back(1.5);

     fun.push_back( Function("mvfHolzman2",26,true,0,true));
     fun[25].bounds.push_back(-10);
     fun[25].bounds.push_back(10);
     for(int i=0; i<26; i++)
          fun[25].atPoint.push_back(0);

     fun.push_back( Function("mvfSumSquares",50,true,0,true));
     fun[26].bounds.push_back(-10);
     fun[26].bounds.push_back(10);
     for(int i=0; i<50; i++)
          fun[26].atPoint.push_back(0);


     fun.push_back( Function("mvfKowalik",4,true,0.0003074861,true));
     fun[27].bounds.push_back(-5);
     fun[27].bounds.push_back(5);
     fun[27].atPoint.push_back(0.192833);
     fun[27].atPoint.push_back(0.190836);
     fun[27].atPoint.push_back(0.123117);
     fun[27].atPoint.push_back(0.135766);

     fun.push_back( Function("mvfHosaki",2,true,-2.3458,true));
     fun[28].bounds.push_back(0);
     fun[28].bounds.push_back(4);
     fun[28].atPoint.push_back(4);
     fun[28].atPoint.push_back(2);

     fun.push_back( Function("mvfLangerman",1,true,-1.5,true));
     fun[29].bounds.push_back(0);
     fun[29].bounds.push_back(10);

     fun.push_back( Function("mvfLeon",2,true,0,true));
     fun[30].bounds.push_back(-10);
     fun[30].bounds.push_back(10);
     fun[30].atPoint.push_back(1);
     fun[30].atPoint.push_back(1);

     fun.push_back( Function("mvfLevy",4,true,-21.502356,true));
     fun[31].bounds.push_back(-10);
     fun[31].bounds.push_back(10);
     for(int i=0; i<3; i++)
          fun[31].atPoint.push_back(1);
     fun[31].atPoint.push_back(-9.752356);

     fun.push_back( Function("mvfLevy",7,true,-11.504403,true));
     fun[32].bounds.push_back(-10);
     fun[32].bounds.push_back(10);
     for(int i=0; i<6; i++)
          fun[32].atPoint.push_back(1);
     fun[32].atPoint.push_back(-4.754402);

     fun.push_back( Function("mvfMatyas",2,true,0,true));
     fun[33].bounds.push_back(-10);
     fun[33].bounds.push_back(10);
     fun[33].atPoint.push_back(0);
     fun[33].atPoint.push_back(0);

     fun.push_back( Function("mvfTrecanni",2,true,0,true));
     fun[34].bounds.push_back(-5);
     fun[34].bounds.push_back(5);
     fun[34].atPoint.push_back(-2);
     fun[34].atPoint.push_back(0);

     fun.push_back( Function("mvfMcCormick",2,true,-4.44201,false));
     fun[35].bounds.push_back(-1.5);
     fun[35].bounds.push_back(4);
     fun[35].bounds.push_back(-3);
     fun[35].bounds.push_back(4);



     double valMich=22*(-0.966);
     fun.push_back( Function("mvfMichalewitz",22,true,valMich,true));
     fun[36].bounds.push_back(0);
     fun[36].bounds.push_back(3.141592653589793);


     fun.push_back( Function("mvfMultimod",30,true,0,true));
     fun[37].bounds.push_back(-10);
     fun[37].bounds.push_back(10);
     for(int i=0; i<30; i++)
          fun[37].atPoint.push_back(0);

     fun.push_back( Function("mvfNeumaierPerm",2,true,0,true));
     fun[38].bounds.push_back(-31);
     fun[38].bounds.push_back(31);
     for(int i=0; i<2; i++)
          fun[38].atPoint.push_back(i+1);

     fun.push_back( Function("mvfShekel4_5",4,true,-10.1532,true));
     fun[39].bounds.push_back(0);
     fun[39].bounds.push_back(10);
     fun[39].atPoint.push_back(4.00004);
     fun[39].atPoint.push_back(4.00013);
     fun[39].atPoint.push_back(4.00004);
     fun[39].atPoint.push_back(4.00013);

     fun.push_back( Function("mvfNeumaierPowersum",4,true,0,true));
     fun[40].bounds.push_back(0);
     fun[40].bounds.push_back(4);
     fun[40].atPoint.push_back(1);
     fun[40].atPoint.push_back(2);
     fun[40].atPoint.push_back(2);
     fun[40].atPoint.push_back(3);


     fun.push_back( Function("mvfShekel4_10",4,true,-10.5364,true));// (4.00075,4.00059,3.99966,3.99951)
     fun[41].bounds.push_back(0);
     fun[41].bounds.push_back(10);
     fun[41].atPoint.push_back(4.00075);
     fun[41].atPoint.push_back(4.00059);
     fun[41].atPoint.push_back(3.99966);
     fun[41].atPoint.push_back(3.99951);


     fun.push_back( Function("mvfPaviani",10,true,-45.7784,true));
     fun[42].bounds.push_back(2.0001);
     fun[42].bounds.push_back(9.9999);
     fun[42].atPoint.push_back(9.340266);
     fun[42].atPoint.push_back(9.340266);

     fun.push_back( Function("mvfTrefethen4",2,true,-3.30686865,false));
     fun[43].bounds.push_back(-6.5);
     fun[43].bounds.push_back(6.5);
     fun[43].bounds.push_back(-4.5);
     fun[43].bounds.push_back(4.5);
     fun[43].atPoint.push_back(-0.0244031);
     fun[43].atPoint.push_back(0.2106124);


     fun.push_back( Function("mvfShekel4_7",4,true,-10.4029,true));   //(4.00057,4.00069,3.99949,3.99961)
     fun[44].bounds.push_back(0);
     fun[44].bounds.push_back(10);
     fun[44].atPoint.push_back(4.00057);
     fun[44].atPoint.push_back(4.00069);
     fun[44].atPoint.push_back(3.99949);
     fun[44].atPoint.push_back(3.99961);


     fun.push_back( Function("mvfRastrigin",19,true,0,true));
     fun[45].bounds.push_back(-5.12);
     fun[45].bounds.push_back(5.12);
     for(int i=0; i<19; i++)
          fun[45].atPoint.push_back(0);

     fun.push_back( Function("mvfRastrigin2",2,true,0,true));
     fun[46].bounds.push_back(-5.12);
     fun[46].bounds.push_back(5.12);
     for(int i=0; i<2; i++)
          fun[46].atPoint.push_back(0);


     fun.push_back( Function("mvfRosenbrock",2,true,0,true));
     fun[47].bounds.push_back(-10);
     fun[47].bounds.push_back(10);
     for(int i=0; i<2; i++)
          fun[47].atPoint.push_back(-1);

     fun.push_back( Function("mvfSchaffer1",2,true,0,true));
     fun[48].bounds.push_back(-100);
     fun[48].bounds.push_back(100);
     for(int i=0; i<2; i++)
          fun[48].atPoint.push_back(0);


     fun.push_back( Function("mvfSchaffer2",2,true,0,true));
     fun[49].bounds.push_back(-100);
     fun[49].bounds.push_back(100);
     for(int i=0; i<2; i++)
          fun[49].atPoint.push_back(0);

     fun.push_back( Function("mvfSchwefel1_2",100,true,0,true));
     fun[50].bounds.push_back(-10);
     fun[50].bounds.push_back(10);
     for(int i=0; i<100; i++)
          fun[50].atPoint.push_back(0);


     fun.push_back( Function("mvfSchwefel2_21",100,true,0,true));
     fun[51].bounds.push_back(-10);
     fun[51].bounds.push_back(10);
     for(int i=0; i<100; i++)
          fun[51].atPoint.push_back(0);

     fun.push_back( Function("mvfSchwefel2_22",30,true,0,true));
     fun[52].bounds.push_back(-10);
     fun[52].bounds.push_back(10);
     for(int i=0; i<30; i++)
          fun[52].atPoint.push_back(0);


     fun.push_back( Function("mvfShubert",2,true,-24.062499,true));
     fun[53].bounds.push_back(-10);
     fun[53].bounds.push_back(10);
     fun[53].atPoint.push_back(-6.774576);
     fun[53].atPoint.push_back(-6.774576);
     fun[53].atPoint.push_back(5.791794);
     fun[53].atPoint.push_back(5.791794);

     fun.push_back( Function("mvfZettl",2,true,-0.003791,true));
     fun[54].bounds.push_back(-10);
     fun[54].bounds.push_back(10);
     fun[54].atPoint.push_back(-0.0299);
     fun[54].atPoint.push_back(0);


     fun.push_back( Function("mvfShubert3",2,true,-24.062499,true));
     fun[55].bounds.push_back(-100);
     fun[55].bounds.push_back(100);
     fun[55].atPoint.push_back(-6.774576);
     fun[55].atPoint.push_back(-6.774576);
     fun[55].atPoint.push_back(5.791794);
     fun[55].atPoint.push_back(5.791794);


     fun.push_back( Function("mvfSphere",70,true,0,true));
     fun[56].bounds.push_back(-10);
     fun[56].bounds.push_back(10);
     for(int i=0; i<100; i++)
          fun[56].atPoint.push_back(0);


     fun.push_back( Function("mvfSphere2",70,true,0,true));
     fun[57].bounds.push_back(-10);
     fun[57].bounds.push_back(10);
     for(int i=0; i<100; i++)
          fun[57].atPoint.push_back(0);
}


problem1::problem1(): Problem()
{
     setNumberOfProblems(58);
     initFun();
     setFunction(0);
}
void problem1::setFunction(unsigned int number)
{
     getCoordinates().clear();
     functionNumber=number;
     if(fun[number].dim==0)
          fun[number].dim=7;
     setDimention(fun[number].dim);

     Coordinate coor1(fun[number].bounds[0], fun[number].bounds[1]);
     setCoordinate(coor1);

     if(fun[number].isSameBoundryForAll) {
          for(int k=1; k<getDimention(); k++)
               setCoordinate(coor1);

     } else
          for(int k=1; k<getDimention(); k++) {
               Coordinate coor2(fun[number].bounds[2*k], fun[number].bounds[2*k+1]);
               setCoordinate(coor2);
          }
#if CLI_MODE==1
     printFunction(number);
     #endif
}

double problem1::computeValue(const std::vector<double> & populationMember)
{
     double value=0.0;
     switch(functionNumber) {
     case 0:
          value=mvfcpp::mvfAckley(getDimention(),populationMember);
          break;
     case 1:
          value=mvfcpp::mvfBeale(getDimention(),populationMember);
          break;
     case 2:
          value=mvfcpp::mvfBohachevsky1(getDimention(),populationMember);
          break;
     case 3:
          value=mvfcpp::mvfBohachevsky2(getDimention(),populationMember);
          break;
     case 4:
          value=mvfcpp::mvfBooth(getDimention(),populationMember);
          break;
     case 5:
          value=mvfcpp::mvfBoxBetts(getDimention(),populationMember);
          break;
     case 6:
          value=mvfcpp::mvfBranin(getDimention(),populationMember);
          break;
     case 7:
          value=mvfcpp::mvfBranin2(getDimention(),populationMember);
          break;
     case 8:
          value=mvfcpp::mvfCamel3(getDimention(),populationMember);
          break;
     case 9:
          value=mvfcpp::mvfCamel6(getDimention(),populationMember);
          break;
     case 10:
          value=mvfcpp::mvfChichinadze(getDimention(),populationMember);
          break;
     case 11:
          fun[11].bounds[0]=0;
          value=mvfcpp::mvfCola(getDimention(),populationMember);
          break;
     case 12:
          value=mvfcpp::mvfColville(getDimention(),populationMember);
          break;
     case 13:
          value=mvfcpp::mvfCorana(getDimention(),populationMember);
          break;
     case 14:
          value=mvfcpp::mvfEasom(getDimention(),populationMember);
          break;
     case 15:
          value=mvfcpp::mvfStep(getDimention(),populationMember);
          break;
     case 16:
          value=mvfcpp::mvfExp2(getDimention(),populationMember);
          break;
     case 17:
          value=mvfcpp::mvfGear(getDimention(),populationMember);
          break;
     case 18:
          value=mvfcpp::mvfGoldsteinPrice(getDimention(),populationMember);
          break;
     case 19:
          value=mvfcpp::mvfGriewank(getDimention(),populationMember);
          break;
     case 20:
          value=mvfcpp::mvfHansen(getDimention(),populationMember);
          break;
     case 21:
          value=mvfcpp::mvfHartman3(getDimention(),populationMember);
          break;
     case 22:
          value=mvfcpp::mvfHartman6(getDimention(),populationMember);
          break;
     case 23:
          value=mvfcpp::mvfHimmelblau(getDimention(),populationMember);
          break;
     case 24:
          value=mvfcpp::mvfHolzman1(getDimention(),populationMember);
          break;
     case 25:
          value=mvfcpp::mvfHolzman2(getDimention(),populationMember);
          break;
     case 26:
          value=mvfcpp::mvfSumSquares(getDimention(),populationMember);
          break;
     case 27:
          value=mvfcpp::mvfKowalik(getDimention(),populationMember);
          break;
     case 28:
          value=mvfcpp::mvfHosaki(getDimention(),populationMember);
          break;
     case 29:
          value=mvfcpp::mvfLangerman(getDimention(),populationMember);
          break;
     case 30:
          value=mvfcpp::mvfLeon(getDimention(),populationMember);
          break;
     case 31:
          value=mvfcpp::mvfLevy(getDimention(),populationMember);
          break;
     case 32:
          value=mvfcpp::mvfLevy(getDimention(),populationMember);
          break;
     case 33:
          value=mvfcpp::mvfMatyas(getDimention(),populationMember);
          break;
     case 34:
          value=mvfcpp::mvfTrecanni(getDimention(),populationMember);
          break;
     case 35:
          value=mvfcpp::mvfMcCormick(getDimention(),populationMember);
          break;
     case 36:
          value=mvfcpp::mvfMichalewitz(getDimention(),populationMember);
          break;
     case 37:
          value=mvfcpp::mvfMultimod(getDimention(),populationMember);
          break;
     case 38:
          value=mvfcpp::mvfNeumaierPerm(getDimention(),populationMember);
          break;
     case 39:
          value=mvfcpp::mvfShekel4_5(getDimention(),populationMember);
          break;
     case 40:
          value=mvfcpp::mvfNeumaierPowersum(getDimention(),populationMember);
          break;
     case 41:
          value=mvfcpp::mvfShekel4_10(getDimention(),populationMember);
          break;
     case 42:
          value=mvfcpp::mvfPaviani(getDimention(),populationMember);
          break;
     case 43:
          value=mvfcpp::mvfTrefethen4(getDimention(),populationMember);
          break;
     case 44:
          value=mvfcpp::mvfShekel4_7(getDimention(),populationMember);
          break;
     case 45:
          value=mvfcpp::mvfRastrigin(getDimention(),populationMember);
          break;
     case 46:
          value=mvfcpp::mvfRastrigin2(getDimention(),populationMember);
          break;
     case 47:
          value=mvfcpp::mvfRosenbrock(getDimention(),populationMember);
          break;
     case 48:
          value=mvfcpp::mvfSchaffer1(getDimention(),populationMember);
          break;
     case 49:
          value=mvfcpp::mvfSchaffer2(getDimention(),populationMember);
          break;
     case 50:
          value=mvfcpp::mvfSchwefel1_2(getDimention(),populationMember);
          break;
     case 51:
          value=mvfcpp::mvfSchwefel2_21(getDimention(),populationMember);
          break;
     case 52:
          value=mvfcpp::mvfSchwefel2_21(getDimention(),populationMember);
          break;
     case 53:
          value=mvfcpp::mvfShubert(getDimention(),populationMember);
          break;
     case 54:
          value=mvfcpp::mvfZettl(getDimention(),populationMember);
          break;
     case 55:
          value=mvfcpp::mvfShubert3(getDimention(),populationMember);
          break;
     case 56:
          value=mvfcpp::mvfSphere(getDimention(),populationMember);
          break;
     case 57:
          value=mvfcpp::mvfSphere2(getDimention(),populationMember);
          break;
     default:
          break;
     }
     return value;
}


void problem1::printFunction(int i)
{
     if(i<getNumberOfProblems()) {
          std::cout<<fun[i].name<<",  dimention: "<<fun[i].dim<<", boundries:  ";
          for(int k=0; k<getDimention(); k++)
               getCoordinates()[k].printCoordinate();
          std::cout<<" minimum is: "<<fun[i].min<<" , at [";
          for(int j=0; j<fun[i].atPoint.size(); j++)
               std::cout<<fun[i].atPoint[j]<<", ";
          std::cout<<"]\n";
     }
}

